#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

//int main()
//{
//	vector<int> nums;
//	sort(nums.begin(), nums.end(), greater<int>());
//
//	return 0;
//}

#include <iostream>
using namespace std;


int a[11];

int main()
{
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) cin >> a[i];

    int count = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == i) count++;
    }

    long long sum = 1;
    for (int i = 1; i <= count; i++) sum *= i;

    cout << sum << '\n';

    return 0;
}